package com.aaa.ssm.controller;

import com.aaa.ssm.dao.DeptDao;
import com.aaa.ssm.entity.Dept;
import com.aaa.ssm.service.DeptService;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import com.aaa.ssm.util.ResultUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @FileName: DeptController
 */
@RestController
@RequestMapping("dept") //请求路径
public class DeptController extends BaseController {
    // 依赖注入
//    @Resource
    @Autowired
    private DeptService deptService;

    /**
     * 根据参数分页查询
     * @param page
     * @return
     */
    @PostMapping("queryByPage") //页面的Ajax请求时，get请求无法携带body
//    @ResponseBody
    public Result queryByPage(@RequestBody Page<Dept> page){
            return ResultUtil.success(deptService.queryByPage(page));
    }


    /**
     * 部门添加
     * @param dept
     * @return
     */
    @PostMapping("add")
//    @ResponseBody
    public Result add(@RequestBody Dept dept) {
        int i = deptService.add(dept);
            return ResultUtil.success(i);

    }

    /**
     * 部门更新
     * @param dept
     * @return
     */

    @PutMapping("update")
//    @ResponseBody //把返回对象转成json字符串
    public Result update(@RequestBody Dept dept) {
        int i = deptService.update(dept);

            return ResultUtil.success(i);

    }

    /**
     * 根据编号删除
     * @param deptNo
     * @return
     */
    @DeleteMapping("deleteById")
//    @ResponseBody
    public Result deleteById( Integer deptNo) {
        int i = deptService.deleteById(deptNo);

            return ResultUtil.success(i);

    }

    /**
     * 根据编号查询对象
     * @param deptNo
     * @return
     */

    @GetMapping("queryById")
//    @ResponseBody
    public Result queryById(Integer deptNo) {
        Dept dept = deptService.queryById(deptNo);
            return ResultUtil.success(dept);
    }
}
